<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>新增角色</title>
    <link href="/static/lib/PearAdmin/component/pear/css/pear.css" rel="stylesheet">
    <link href="/static/css/sitesmanager.css" rel="stylesheet">
</head>
<body class="pear-container">
<div class="body-card layui-card padding">
    <form id="saveRole" class="layui-form" action="javascript:void(0);">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="color-warn">*</span>
                名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" placeholder="请输入角色名称" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                备注</label>
            <div class="layui-input-block">
                <input type="text" name="remark" placeholder="请输入备注" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="pear-btn pear-btn-primary" lay-submit lay-filter="roleForm">立即提交</button>
                <button type="reset" class="pear-btn">重置</button>
            </div>
        </div>
    </form>
</div>

<script src="/static/lib/PearAdmin/component/layui/layui.js"></script>
<script src="/static/lib/PearAdmin/component/pear/pear.js"></script>
<script>
    layui.use([ 'form', 'element', 'popup'], function() {
        let form = layui.form;
        let popup = layui.popup;
        let $ = layui.$;//使用layui内置的jQuery

        //表单提交
        form.on('submit(roleForm)', function(data) {
            // 验证：表单字段设置属性，自动验证
            // 提交
            let $form = $("#saveRole");
            $.post("/role/save", $form.serialize(), function(data){
                if("1"==data.state){
                    popup.success("保存成功", function() {
                        //当你在iframe页面关闭自身时
                        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                } else {
                    popup.failure(data.msg);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
